<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      button {
        border-radius: 5px;
        color: #fff;
      }
    </style>
  </head>
  <body>
    <div id="app">
      <h2>封装按钮组件</h2>
      <van-button type="primary">主要按钮</van-button>
      <van-button type="success" size="mini">成功按钮</van-button>
      <van-button type="default">默认按钮</van-button>
    </div>

    <script src="./vue.js"></script>
    <script>
      const VanButton = {
        data() {
          return {
            colorObj: {
              primary: "blue",
              success: "green",
              warning: "yellow",
              danger: "red",
              default: "white",
            },
            widthObj: {
              large: 80,
              small: 60,
              mini: 40,
            },
            heightObj: {
              large: 40,
              small: 30,
              mini: 20,
            },
          };
        },
        props: {
          type: {
            type: String,
            default: "default",
            validator(value) {
              //primary success warning danger
              return [
                "primary",
                "success",
                "warning",
                "danger",
                "default",
              ].includes(value);
            },
          },
          size: {
            type: String,
            default: "large",
            validator(value) {
              //primary success warning danger
              return ["small", "mini", "large"].includes(value);
            },
          },
        },
        template: `
          <button :style="{ background: colorObj[type], width: widthObj[size] + 'px', height: heightObj[size] + 'px' }"><slot></slot></button>
        `,
      };

      Vue.createApp({
        data() {
          return {};
        },
        components: {
          VanButton,
        },
      }).mount("#app");
    </script>
  </body>
</html>
